\documentclass[twoside,a4paper]{ctexart}
\usepackage{geometry}
\geometry{margin=1.5cm, vmargin={0pt,1cm}}
\setlength{\topmargin}{-1cm}
\setlength{\paperheight}{29.7cm}
\setlength{\textheight}{25.3cm}

% useful packages.
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{enumerate}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage{layout}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{subfigure}

% some common command

\title{{\Huge{\textbf{Project 4}}}\\——MOL}
\author{邵柯欣}
\date{\today}


\newcommand{\dif}{\mathrm{d}}
\newcommand{\avg}[1]{\left\langle #1 \right\rangle}
\newcommand{\difFrac}[2]{\frac{\dif #1}{\dif #2}}
\newcommand{\pdfFrac}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\OFL}{\mathrm{OFL}}
\newcommand{\UFL}{\mathrm{UFL}}
\newcommand{\fl}{\mathrm{fl}}
\newcommand{\op}{\odot}
\newcommand{\Eabs}{E_{\mathrm{abs}}}
\newcommand{\Erel}{E_{\mathrm{rel}}}

\begin{document}

\maketitle

\pagestyle{fancy}
\fancyhead{}
\lhead{邵柯欣 (3200103310)}
\chead{Numerical PDE project 4}
\rhead{\today}

\section*{I. 文件介绍}
整个作业文件由三个子文件夹（src,doc,fig）构成，分别用来存放代码，报告，图片．所有文件通过$Ｍakefile$管理．只需在$Ｍakefile$所在目录下输入$make$，即可生成测试代码的可执行文件；在改目录下输入$clean$，就能删除生成的文件，回到初始状态． 

\section*{II src代码介绍}
在main.cpp文件中根据作业题目要求实现对各种求解器的测试和结果输出，并将结果保存在result.txt文件中，然后用python代码根据数据画出可视化的结果图片（python代码与结果图片保存在与src同一级的fig文件中）。

具体的求解器代码放在不同的“*.h”头文件中，

\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
  \textbf{thetaM.h} 包含　theta\_method 类 \\
  theta\_method(double \_theta, double \_r, double \_h)
\end{mdframed}

\begin{itemize}
\item theta\_method 类用来实现$\theta-method$求解热方程．
\item 通过设置不同的$\theta$值，可以实现不同的求解方法，如$\theta = 0$是$FTCS$ method，$\theta = \frac{1}{2}$是$Crank-Nicolson$ method，$\theta = 1$是$BTCS$ method.
\end{itemize}

\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
  \textbf{collocationM.h} 包含　twostage\_collocation\_method 类, onestage\_GaussLegendre\_RK\_method 类\\
  构造函数分别为:\\
  twostage\_collocation\_method(double \_r, double \_h)\\
  onestage\_GaussLegendre\_RK\_method(double \_r, double \_h)
\end{mdframed}

\begin{itemize}
\item twostage\_collocation\_method 类 用来实现 Example 11.258 中的 2-stage collocation method 求解热方程．
\item onestage\_GaussLegendre\_RK\_method 类 用来实现 Example 11.227 中的 1-stage Gauss-Legendre RK method 求解热方程．（因为其可以看成是 1-stage 的 collocation method，所以也放在 collocation\_method.h 中）
\end{itemize}

\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
  \textbf{leapfrogM.h} 包含　leapfrog\_method 类
\end{mdframed}

\begin{itemize}
\item leapfrog\_method 类 根据 Definition 12.63 实现 leapfrog method 求解平流方程．
\end{itemize}

\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
  \textbf{LFM.h} 包含 Lax\_Friedrichs\_method 类
\end{mdframed}

\begin{itemize}
\item Lax\_Friedrichs\_method 类 根据 Definition 12.64 实现 Lax-Friedrichs method 求解平流方程．
\end{itemize}

\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
  \textbf{LWM.h} 包含 Lax\_Wendroff\_method 类
\end{mdframed}

\begin{itemize}
\item Lax\_Wendroff\_method 类 根据 Definition 12.70 实现 Lax-Wendroff method 求解平流方程．
\end{itemize}

\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
  \textbf{upwindM.h} 包含 upwind\_method 类
\end{mdframed}

\begin{itemize}
\item upwind\_method 类 根据 Definition 12.75 实现 upwind method 求解平流方程．
\end{itemize}

\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
  \textbf{BWM.h} 包含 Beam\_Warming\_method 类
\end{mdframed}

\begin{itemize}
\item Beam\_Warming\_method 类 根据 Definition 12.81 实现 Beam-Warming method 求解平流方程．
\end{itemize}

不同的求解器使用起来基本一致,只需在头文件中引用对应的"*.h"文件,然后构造使用求解器即可,以 BTCS method 为例,对应的测试代码如下:
\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
\begin{verbatim}
  #include "thetaM.h"
  int main(){
    double h = 0.05, r = 1, theta = 0;
    theta_method TM(theta, r, h);
    vector<double> U;
    U = TM.Solver(1);// 括号中的参数为时间前进的次数，只有求解热方程时需要传入该参数；
  }
\end{verbatim}
\end{mdframed}

\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
  \textbf{function.h} 
\end{mdframed}

\begin{itemize}
\item u0 函数 热方程(12.3)的初始条件$u(x,0)$.
\item u0 函数 平流方程(12.55)的初始条件$u(x,0)$．
\end{itemize}

\begin{mdframed}[hidealllines=true,backgroundcolor=blue!20]
  \textbf{MatrixV.h} 
\end{mdframed}

\begin{itemize}
\item MatrixV 类 根据求解方法的需求生成相应的常数矩阵.
\item 重载了+-*等运算符，实现了矩阵、向量和常数之间常用的运算．
\item 重载了print()函数,实现了对矩阵和向量的输出呈现.
\end{itemize}

\section*{III. 测试结果展示}

\subsection*{MOL for the heat equation}
The test problem (Example 12.38):
$$u_t = \nu u_{xx} \quad \Omega := (0,1) \times (0,T)$$
with $\nu = 1$ and the boundary conditions $u(0,t) = u(1,t) = 0$ and the initial condition
\begin{equation}
  u(x,0) = \phi(x) =
  \left\{
  \begin{matrix}
    20(x - \frac{9}{20}), & x \in [\frac{9}{20}, \frac{1}{2}), \\
    -20(x - \frac{11}{20}), & x \in [\frac{1}{2}, \frac{11}{20}), \\
    0, & otherwise.
  \end{matrix}
  \right.
\end{equation}
\subsubsection*{(a) reproduce all polts in Example 12.38}
After 1, 2, and 10 time steps, the Crank-Nicolson method with $r = 1$ gives results as follows.
\begin{figure}[htbp]
	\centering
	\subfigure[t = k] {\includegraphics[width=.3\textwidth]{../fig/CN11.png}}
	\subfigure[t = 2k] {\includegraphics[width=.3\textwidth]{../fig/CN12.png}}
	\subfigure[t = 10k] {\includegraphics[width=.3\textwidth]{../fig/CN13.png}}
	\caption{the Crank-Nicolson method with $r = 1$}
	\label{fig_E1}
\end{figure}
Crank-Nicolson with $r = 2$ gives results as follows.
\begin{figure}[htbp]
	\centering
	\subfigure[t = k] {\includegraphics[width=.3\textwidth]{../fig/CN21.png}}
	\subfigure[t = 2k] {\includegraphics[width=.3\textwidth]{../fig/CN22.png}}
	\subfigure[t = 10k] {\includegraphics[width=.3\textwidth]{../fig/CN23.png}}
	\caption{the Crank-Nicolson method with $r = 2$}
	\label{fig_E2}
\end{figure}

The BTCS with $r = 1$ gives results as follows.
\begin{figure}[htbp]
	\centering
	\subfigure[t = k] {\includegraphics[width=.3\textwidth]{../fig/BTCS11.png}}
	\subfigure[t = 2k] {\includegraphics[width=.3\textwidth]{../fig/BTCS12.png}}
	\subfigure[t = 10k] {\includegraphics[width=.3\textwidth]{../fig/BTCS13.png}}
	\caption{The BTCS with $r = 1$}
	\label{fig_E3}
\end{figure}

The collocation method in Example 11.258 with $r = 1$ gives results as follows.
\begin{figure}[htbp]
	\centering
	\subfigure[t = k] {\includegraphics[width=.3\textwidth]{../fig/CO31.png}}
	\subfigure[t = 2k] {\includegraphics[width=.3\textwidth]{../fig/CO32.png}}
	\subfigure[t = 10k] {\includegraphics[width=.3\textwidth]{../fig/CO33.png}}
	\caption{The collocation method with $r = 1$}
	\label{fig_E4}
\end{figure}
\subsubsection*{(b) BTCS and the collocation method in Example 11.258 with $r = \frac{1}{2h}$}
The collocation method in Example 11.258:
$$c_1 = \frac{1}{3}, c_2 = 1$$
The BTCS with $r = \frac{1}{2h}$ gives results as follows.
\begin{figure}[htbp]
	\centering
	\subfigure[t = k] {\includegraphics[width=.3\textwidth]{../fig/BTCS21.png}}
	\subfigure[t = 2k] {\includegraphics[width=.3\textwidth]{../fig/BTCS22.png}}
	\subfigure[t = 10k] {\includegraphics[width=.3\textwidth]{../fig/BTCS23.png}}
	\caption{The BTCS with $r = \frac{1}{2h}$}
	\label{fig_E5}
\end{figure}

The collocation method in Example 11.258 with $r = \frac{1}{2h}$ gives results as follows.
\begin{figure}[htbp]
	\centering
	\subfigure[t = k] {\includegraphics[width=.3\textwidth]{../fig/CO21.png}}
	\subfigure[t = 2k] {\includegraphics[width=.3\textwidth]{../fig/CO22.png}}
	\subfigure[t = 10k] {\includegraphics[width=.3\textwidth]{../fig/CO23.png}}
	\caption{The collocation method with $r = \frac{1}{2h}$}
	\label{fig_E6}
\end{figure}
\subsubsection*{(c) FTCS with $r = \frac{1}{2}, 1$}
The FTCS with $r = \frac{1}{2}$ gives results as follows.
\begin{figure}[htbp]
	\centering
	\subfigure[t = k] {\includegraphics[width=.3\textwidth]{../fig/FTCS01.png}}
	\subfigure[t = 2k] {\includegraphics[width=.3\textwidth]{../fig/FTCS02.png}}
	\subfigure[t = 10k] {\includegraphics[width=.3\textwidth]{../fig/FTCS03.png}}
	\caption{The FTCS with $r = \frac{1}{2}$}
	\label{fig_E7}
\end{figure}

The FTCS with $r = 1$ gives results as follows.
\begin{figure}[htbp]
	\centering
	\subfigure[t = k] {\includegraphics[width=.3\textwidth]{../fig/FTCS11.png}}
	\subfigure[t = 2k] {\includegraphics[width=.3\textwidth]{../fig/FTCS12.png}}
	\subfigure[t = 10k] {\includegraphics[width=.3\textwidth]{../fig/FTCS13.png}}
	\caption{The FTCS with $r = 1$}
	\label{fig_E8}
\end{figure}
\subsubsection*{(d) the 1-stage Gauss-Legendre RK method in Example 11.227 with $r = 1, \frac{1}{2h}$}
The 1-stage Gauss-Legendre RK method in Example 11.227:
$$c_1 = \frac{1}{2}$$
the 1-stage Gauss-Legendre RK method in Example 11.227 with $r = 1$
\begin{figure}[htbp]
	\centering
	\subfigure[t = k] {\includegraphics[width=.3\textwidth]{../fig/GLRK11.png}}
	\subfigure[t = 2k] {\includegraphics[width=.3\textwidth]{../fig/GLRK12.png}}
	\subfigure[t = 10k] {\includegraphics[width=.3\textwidth]{../fig/GLRK13.png}}
	\caption{The Gauss-Legendre RK method with $r = 1$}
	\label{fig_E9}
\end{figure}

the 1-stage Gauss-Legendre RK method in Example 11.227 with $r = \frac{1}{2h}$
\begin{figure}[htbp]
	\centering
	\subfigure[t = k] {\includegraphics[width=.3\textwidth]{../fig/GLRK21.png}}
	\subfigure[t = 2k] {\includegraphics[width=.3\textwidth]{../fig/GLRK22.png}}
	\subfigure[t = 10k] {\includegraphics[width=.3\textwidth]{../fig/GLRK23.png}}
	\caption{The FTCS with $r = \frac{1}{2h}$}
	\label{fig_E10}
\end{figure}
\subsubsection*{(e) compare results and explain}
\subsection*{MOL for the advection equation}
The advection equation:
$$u_t + u_x = 0$$
with initial condition
$$u(x,0) = exp(-20(x-2^2)) + exp(-(x-5)^2)$$
Reproduce all results in Example 12.93.

We solve this problem with $h = 0.05$ to $T = 17$, using the leapfrog method, the Lax-Friedrichs method, the Lax-Wendroff method, the upwind method and the Beam-Warming method.
\begin{figure}[htbp]
  \centering
  \subfigure[initial condition] {\includegraphics[width=.4\textwidth]{../fig/test0.png}}
  \subfigure[leapfrog] {\includegraphics[width=.4\textwidth]{../fig/test1.png}}
  \subfigure[Lax-Friedrichs] {\includegraphics[width=.4\textwidth]{../fig/test3.png}}
  \subfigure[Lax-Wendroff] {\includegraphics[width=.4\textwidth]{../fig/test4.png}}
  \subfigure[upwind] {\includegraphics[width=.4\textwidth]{../fig/test6.png}}
  \subfigure[Beam-Warming] {\includegraphics[width=.4\textwidth]{../fig/test7.png}}
  \caption{The result with $k = 0.8h$}
  \label{fig_E10}
\end{figure}

\begin{figure}[htbp]
  \centering
  \subfigure[leapfrog] {\includegraphics[width=.4\textwidth]{../fig/test2.png}}
  \subfigure[Lax-Wendroff] {\includegraphics[width=.4\textwidth]{../fig/test5.png}}
  \caption{The result with $k = h$}
  \label{fig_E10}
\end{figure}
\end{document}
